<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <form action="">
        <button type="reset">重置按钮</button>
        <hr>
        <!-- 第一列 -->
        <label>原始数据输入</label><input type="text" id="in1">
        <br>
        <!-- 按钮 -->
        <button type="button" onclick="rounding('round')">取整（四舍五入）</button>
        <button type="button" onclick="rounding('ceil')">取整（大于）</button>
        <button type="button" onclick="rounding('floor')">取整（小于）</button>
        <br>
        <button type="button" onclick="basic('sqrt')">平方根</button>
        <button type="button" onclick="basic('abs')">绝对值</button>
        <button type="button" onclick="basic('sin')">正弦值</button>
        <button type="button" onclick="basic('cos')">余弦值</button>
        <br>
        <!--运算结果-->
        <label>运算结果</label><input type="text" id="out1" disabled>

        <hr>
        <!-- 第二列 -->
        <label>原始数据输入</label><input type="text" id="in2"> <input type="text" id="in3"><br>
        <!--按钮-->
        <button type="button" onclick="compareNums('min')">求较小值</button>
        <button type="button" onclick="compareNums('max')">求较大值</button>
        <br>
        <!--运算结果-->
        <label>运算结果</label><input type="text" id="out2" disabled>
    </form>

</div>

<script>

    // 获取结点
    // 输入结点
    let in1 = document.getElementById("in1");
    let in2 = document.getElementById("in2");
    let in3 = document.getElementById("in3");

    // 输出结点
    let out1 = document.getElementById("out1");
    let out2 = document.getElementById("out2");

    // 取整算法
    function rounding(type) {
        let number;
        if (type === "round"){
            number= Math.round(eval(in1.value));
        }else if (type === "ceil"){
            number= Math.ceil(eval(in1.value));
        }else if (type === "floor"){
            number= Math.floor(eval(in1.value));
        }
        out1.value = number;
    }

    // 基本算法
    function basic(type) {
        let number;
        if (type === "sqrt"){
            number= Math.sqrt(eval(in1.value));
        }else if (type === "abs"){
            number= Math.abs(eval(in1.value));
        }else if (type === "sin"){
            number= Math.sin(eval(in1.value));
        }else if (type === "cos"){
            number= Math.cos(eval(in1.value));
        }
        out1.value = number;
    }

    // 比较数的大小
    function compareNums(type) {
        let number;
        if (type === "min"){
            number= Math.min(eval(in2.value),eval(in3.value));
        }else if (type === "max"){
            number= Math.max(eval(in2.value),eval(in3.value));
        }
        out2.value = number;
    }


</script>

</body>
</html>
